package cc.rengu.igas.momp.core.service.trans;

import cc.rengu.igas.momp.common.constant.CommonConstant;
import cc.rengu.igas.momp.common.dao.*;
import cc.rengu.igas.momp.common.dao.impl.*;
import cc.rengu.igas.momp.common.entity.*;
import cc.rengu.igas.momp.common.enums.*;
import cc.rengu.igas.momp.common.util.CommonMessageCheck;
import cc.rengu.igas.momp.common.util.JsonOperation;
import cc.rengu.igas.momp.common.util.MompAmountUtil;
import cc.rengu.igas.momp.facade.bean.*;
import cc.rengu.igas.momp.facade.request.EditCashierCashbackMcDetailRequest;
import cc.rengu.igas.momp.facade.response.EditCashierCashbackMcDetailResponse;
import cc.rengu.oltp.service.base.RadpService;
import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.entity.SysParam;
import cc.rengu.oltp.service.common.enums.ChannelEnum;
import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.utility.bean.PageInfo;
import cc.rengu.oltp.utility.bean.PageResult;
import cc.rengu.oltp.utility.util.*;
import cc.rengu.utility.base.StringUtil;
import cc.rengu.utility.dbs.Database;
import com.alibaba.fastjson.JSONObject;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 收银员返现类活动信息编辑功能实现
 *
 * @author Jinan Liu
 * @version 1.0.0
 * @date 2020/4/1 10:59
 */
public class EditCashierCashbackMcDetailInfoService extends RadpService {

    private String globalInstId;
    private String globalMcNo;
    private String globalTimeStamp;
    private String globalOprId;
    private String globalTxnDate;
    private final static String TABLE_NAME = TableNameEnum.T_M_MC_CCB_INFO.getTableNameCode();
    private String globalOrgId;
    private String globalMchntFlag;
    private String globalFlowNo;
    private boolean merFileFlag = false;
    private String flowAuditStatus = "";
    private String flowTmpAuditStatus = "";
    private String traceNo;
    private BigDecimal zero = BigDecimal.ZERO;
    private boolean auditStatusChangeFlag = false;

    @Override
    protected int bizInit(String s) {
        return CommonConstant.PROCESS_SUCCESS;
    }

    @Override
    protected int bizProcess(String s, int i) {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();

        try {
            globalTimeStamp = new SimpleDateFormat(CommonConstant.TIMESTAMP_FORMAT).format(new Date());
            rglog.info("接口开始处理,开始时间<{}>........", globalTimeStamp);
            EditCashierCashbackMcDetailRequest editCashierCashbackMcDetailRequest = new EditCashierCashbackMcDetailRequest();
            ConvertUtil.convertOutput(editCashierCashbackMcDetailRequest);

            EditCashierCashbackMcDetailResponse editCashierCashbackMcDetailResponse = new EditCashierCashbackMcDetailResponse();
            editCashierCashbackMcDetailResponse.setHeader(editCashierCashbackMcDetailRequest.getHeader());
            BizResponse<EditCashierCashbackMcDetailResponse> bizResponse = new BizResponse<>();
            bizResponse.setResult(editCashierCashbackMcDetailResponse);

            //判断查询类型
            rglog.debug("交易类型:TXN_NUM=<{}> ，交易流水:<{}>", editCashierCashbackMcDetailRequest.getHeader().getTxnNum(), editCashierCashbackMcDetailRequest.getHeader().getTraceNo());

            globalInstId = editCashierCashbackMcDetailRequest.getHeader().getInstId();
            globalOprId = editCashierCashbackMcDetailRequest.getQueryId();
            globalTxnDate = editCashierCashbackMcDetailRequest.getHeader().getTransDate();
            globalOrgId = editCashierCashbackMcDetailRequest.getQueryOrgId();
            if (null == editCashierCashbackMcDetailRequest.getMchntInfoList() || editCashierCashbackMcDetailRequest.getMchntInfoList().isEmpty()) {
                globalMchntFlag = CommonConstant.ZERO_COMMON_CONSTANT;
            } else {
                globalMchntFlag = CommonConstant.ONE_COMMON_CONSTANT;
            }

            String queryType = editCashierCashbackMcDetailRequest.getQueryType();
            String queryRole = editCashierCashbackMcDetailRequest.getQueryRole();
            String oprType = editCashierCashbackMcDetailRequest.getOprType();

            rglog.debug("QUERY_TYPE=<{}>", queryType);
            rglog.debug("QUERY_ID=<{}>", globalOprId);
            rglog.debug("QUERY_ROLE=<{}>", queryRole);
            rglog.debug("OPR_TYPE=<{}>", oprType);

            /* 报文检查 */
            CommonMessageCheck.checkBizMessageHeader(queryType, globalOprId, queryRole, rglog);
            CommonMessageCheck.checkSingleValue(oprType, rglog);

            if (!StringUtil.isNullorEmpty(editCashierCashbackMcDetailRequest.getMcInfoObj().getMcNo())) {
                globalMcNo = editCashierCashbackMcDetailRequest.getMcInfoObj().getMcNo();
            }

            if (!StringUtil.isNullorEmpty(editCashierCashbackMcDetailRequest.getMrctFilePath())) {
                merFileFlag = true;
                rglog.info("收银员返现类营销活动编辑，商户文件路径：" + editCashierCashbackMcDetailRequest.getMrctFilePath());
            }

            checkMchntAndOrgInfo(editCashierCashbackMcDetailRequest);

            // 服务调用
            BizResponse<EditCashierCashbackMcDetailResponse> bizResponseNew = editCashierCashbackMcDetailInfo(
                    editCashierCashbackMcDetailRequest, editCashierCashbackMcDetailResponse, xmlTreeUtil);

            ConvertUtil.convertInput(bizResponseNew.getResult());

        } catch (BizException e) {
            try {
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_CODE, e.getCode());
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_DESC, e.getMessage());
                xmlTreeUtil.setXmlTreeStringValue(CommonConstant.KEY_RESPDESC, e.getMessage());
            } catch (Exception e1) {
                rglog.error(StringUtil.ExceptionToString(e1));
            }
        } catch (Exception e) {
            rglog.error(StringUtil.ExceptionToString(e));
            try {
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_CODE, OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_DESC, OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
                xmlTreeUtil.setXmlTreeStringValue(CommonConstant.KEY_RESPDESC, e.getMessage());
            } catch (Exception e1) {
                rglog.error(StringUtil.ExceptionToString(e));
            }
        }
        rglog.info("接口处理结束,结束时间<{}>,共用<{}>毫秒", new SimpleDateFormat(CommonConstant.TIMESTAMP_FORMAT).format(new Date()), DateUtil.getTimeCost(globalTimeStamp, new SimpleDateFormat(CommonConstant.TIMESTAMP_FORMAT).format(new Date())));
        return CommonConstant.PROCESS_SUCCESS;
    }

    @Override
    protected int bizTerminate(String s) {
        return CommonConstant.PROCESS_SUCCESS;
    }

    /**
     * 收银员返现类活动编辑处理流程
     *
     * @param editCashierCashbackMcDetailRequest  收银员返现类活动信息编辑接口请求对象
     * @param editCashierCashbackMcDetailResponse 收银员返现类活动信息编辑接口应答对象
     * @param xmlTreeUtil                         内部XML树
     * @return cc.rengu.oltp.service.model.BizResponse<cc.rengu.igas.momp.facade.response.EditCashierCashbackMcDetailResponse> 收银员返现类活动信息编辑接口应答对象
     * @throws BizException 异常信息
     * @author Jinan Liu
     * @date 2020/5/21 18:15
     */
    private BizResponse<EditCashierCashbackMcDetailResponse> editCashierCashbackMcDetailInfo(EditCashierCashbackMcDetailRequest editCashierCashbackMcDetailRequest, EditCashierCashbackMcDetailResponse editCashierCashbackMcDetailResponse, XmlTreeUtil xmlTreeUtil)
            throws Exception {

        BizResponse<EditCashierCashbackMcDetailResponse> bizResponse = new BizResponse<>();

        //判断查询类型
        String queryType = editCashierCashbackMcDetailRequest.getQueryType();
        String queryRole = editCashierCashbackMcDetailRequest.getQueryRole();
        String oprType = editCashierCashbackMcDetailRequest.getOprType();

        //判断用户的角色和权限
        if (QueryTypeEnum.BANK_QUERY_TYPE.getQueryTypeCode().equals(queryType)) {

            if (QueryRoleEnum.BANK_BASIC_QUERY_ROLE.getQueryRoleCode().equals(queryRole)) {
                //银行人员录入岗-正式表和临时表所有数据
                rglog.info("银行人员录入岗开始操作");
                //操作类型：保存
                if (OprTypeEnum.EDIT_SAVE.getOprTypeCode().equals(oprType)) {
                    rglog.info("全新保存数据流程开始");
                    // 保存数据是完全新增数据的流程，需要生成营销活动编号
                    if (StringUtil.isNullorEmpty(globalMcNo)) {
                        //如果营销活动编号不存在，说明是全新的营销活动，需要生成一个营销活动编号，并新增全部数据
                        globalMcNo = generateNewMcNo(editCashierCashbackMcDetailRequest.getMcInfoObj());
                        if (!StringUtil.isNullorEmpty(globalMcNo)) {
                            rglog.info("新生成的营销活动编号 MC_NO=<{}>", globalMcNo);
                        }
                        //开启数据库事务
                        String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MOMP_POOL_NAME);
                        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
                        if (null != corporation && !corporation.isEmpty()) {
                            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
                            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
                        }
                        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
                        dbsUtil.dbsBeginTransaction();
                        //全部新增流程，插入数据
                        insertAllMcInfoByBank(dbsUtil, editCashierCashbackMcDetailRequest);
                        //正常结束数据库事务
                        dbsUtil.dbsEndTransaction(true);
                    } else {
                        rglog.info("营销活动已存在,再次保存数据流程开始");
                        /* 如果营销活动编号存在,需要根据当前数据库各状态判断是否可以更新数据 */
                        saveAllMcInfoByBank(xmlTreeUtil, editCashierCashbackMcDetailRequest);
                    }
                    rglog.info("保存数据流程结束");
                    //操作类型：提交审批
                } else if (OprTypeEnum.EDIT_SUBMIT.getOprTypeCode().equals(oprType)) {
                    rglog.info("提交审批流程开始");
                    //提交审批
                    submitMcInfo(editCashierCashbackMcDetailRequest);
                    rglog.info("提交审批流程结束");
                    //操作类型：修改草稿
                } else if (OprTypeEnum.EDIT_DRAFT.getOprTypeCode().equals(oprType)) {
                    rglog.info("修改草稿流程开始");
                    // 修改草稿
                    updateAllDraftMcInfoByBank(xmlTreeUtil, editCashierCashbackMcDetailRequest);
                    rglog.info("修改草稿流程结束");
                } else {
                    rglog.error("当前<{}>角色的查询用户<{}>无权限查看数据!", queryRole, queryType);
                    throw new BizException(RespCodeEnum.NOT_SUPPORTED_OPR_TYPE_ERROR.getRespCode(), RespCodeEnum.NOT_SUPPORTED_OPR_TYPE_ERROR.getRespDesc());
                }
            } else {
                //银行审批岗或银行发布岗
                rglog.error("当前<{}>角色的查询用户<{}>无权限查看数据!", queryRole, queryType);
                throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_QUERY_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_QUERY_ERROR.getRespDesc());
            }
        } else {
            //商户、代理商、收银员或用户
            rglog.error("当前<{}>角色的查询用户<{}>无权限查看数据!", queryRole, queryType);
            throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_QUERY_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_QUERY_ERROR.getRespDesc());
        }

        bizResponse.setRspSysId(ChannelEnum.MOMP.getChannelType());
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());

        editCashierCashbackMcDetailResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        editCashierCashbackMcDetailResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());

        editCashierCashbackMcDetailResponse.setMcNo(globalMcNo);

        bizResponse.setResult(editCashierCashbackMcDetailResponse);

        return bizResponse;
    }

    /**
     * 营销活动信息数据库实体类和接口实体类数据转换
     *
     * @param cashierCashbackMcInfoBean 收银员返现活动基本信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcCashierCashbackInfo 收银员返现类活动信息表
     * @author Jinan Liu
     * @date 2020/5/21 15:18
     */
    private TMMcCashierCashbackInfo convertMcInfo(CashierCashbackMcInfoBean cashierCashbackMcInfoBean) {
        // 检查上传字段 不能为负数
        checkMcInfoObjFieldHasNegativeNumber(cashierCashbackMcInfoBean);

        TMMcCashierCashbackInfo mcCashierCashbackInfo = new TMMcCashierCashbackInfo();
        try {
            /* 法人机构号 */
            mcCashierCashbackInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcCashierCashbackInfo.setMcNo(globalMcNo);
            /* 营销活动名称 */
            if (StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getMcName())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcCashierCashbackInfo.setMcName(cashierCashbackMcInfoBean.getMcName());
            }
            /* 营销活动类型 */
            if (StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getMcType())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcCashierCashbackInfo.setMcType(cashierCashbackMcInfoBean.getMcType());
            }
            /* 营销活动状态 */
            if (StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getMcStatus())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcCashierCashbackInfo.setMcStatus(cashierCashbackMcInfoBean.getMcStatus());
            }
            /* 活动起始日期 */
            if (StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getMcStartDate())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcCashierCashbackInfo.setMcStartDate(cashierCashbackMcInfoBean.getMcStartDate());
            }
            /* 活动截止日期 */
            if (StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getMcEndDate())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcCashierCashbackInfo.setMcEndDate(cashierCashbackMcInfoBean.getMcEndDate());
            }
            /* 活动结束日期 */
            if (StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getMcActualEndDate())) {
                mcCashierCashbackInfo.setMcActualEndDate(cashierCashbackMcInfoBean.getMcEndDate());
            } else {
                mcCashierCashbackInfo.setMcActualEndDate(cashierCashbackMcInfoBean.getMcActualEndDate());
            }
            /* 优惠打款模式 */
            if (StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getDiscountTransferMode())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcCashierCashbackInfo.setDiscountTransferMode(cashierCashbackMcInfoBean.getDiscountTransferMode());
            }
            /* 活动预算 */
            if (!StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getBudget())) {
                mcCashierCashbackInfo.setBudget(MompAmountUtil.getTwoDecimal(cashierCashbackMcInfoBean.getBudget()));
            } else {
                mcCashierCashbackInfo.setBudget(CommonConstant.ZERO_AMOUNT);
            }
            /* 达标条件 */
            if (StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getCriteriaFlag())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcCashierCashbackInfo.setCriteriaFlag(cashierCashbackMcInfoBean.getCriteriaFlag());
            }
            /* 有效交易定义 */
            if (StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getCriteriaLimit())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcCashierCashbackInfo.setCriteriaLimit(MompAmountUtil.getTwoDecimal(cashierCashbackMcInfoBean.getCriteriaLimit()));
            }
            /* 统计周期 */
            if (StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getStatPeriod())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcCashierCashbackInfo.setStatPeriod(cashierCashbackMcInfoBean.getStatPeriod());
            }
            /* 达标交易金额 */
            if (StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getCriteriaAmount())) {
                mcCashierCashbackInfo.setCriteriaAmount(CommonConstant.ZERO_AMOUNT);
            } else {
                mcCashierCashbackInfo.setCriteriaAmount(MompAmountUtil.getTwoDecimal(cashierCashbackMcInfoBean.getCriteriaAmount()));
            }
            /* 达标交易笔数 */
            if (StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getCriteriaQuantity())) {
                mcCashierCashbackInfo.setCriteriaQuantity(CommonConstant.ZERO_COMMON_CONSTANT);
            } else {
                mcCashierCashbackInfo.setCriteriaQuantity(cashierCashbackMcInfoBean.getCriteriaQuantity());
            }
            /* 优惠退出标志 */
            if (StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getTerminationFlagPerson())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcCashierCashbackInfo.setTerminationFlagPerson(cashierCashbackMcInfoBean.getTerminationFlagPerson());
            }
            /* 交易笔数上限 */
            if (!StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getQuantityLimitPerson())) {
                mcCashierCashbackInfo.setQuantityLimitP(cashierCashbackMcInfoBean.getQuantityLimitPerson());
            } else {
                mcCashierCashbackInfo.setQuantityLimitP(CommonConstant.ZERO_COMMON_CONSTANT);
            }
            /* 交易金额上限 */
            if (!StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getAmountLimitPerson())) {
                mcCashierCashbackInfo.setAmountLimitP(MompAmountUtil.getTwoDecimal(cashierCashbackMcInfoBean.getAmountLimitPerson()));
            } else {
                mcCashierCashbackInfo.setAmountLimitP(CommonConstant.ZERO_COMMON_CONSTANT);
            }
            /* 返现金额上限 */
            if (!StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getCashbackLimitPerson())) {
                mcCashierCashbackInfo.setCashbackLimitP(MompAmountUtil.getTwoDecimal(cashierCashbackMcInfoBean.getCashbackLimitPerson()));
            } else {
                mcCashierCashbackInfo.setCashbackLimitP(CommonConstant.ZERO_COMMON_CONSTANT);
            }
            /* 优惠退出标志 */
            if (StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getTerminationFlagMc())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcCashierCashbackInfo.setTerminationFlagMc(cashierCashbackMcInfoBean.getTerminationFlagMc());
            }
            /* 交易笔数上限 */
            if (!StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getQuantityLimitMc())) {
                mcCashierCashbackInfo.setQuantityLimitMc(cashierCashbackMcInfoBean.getQuantityLimitMc());
            } else {
                mcCashierCashbackInfo.setQuantityLimitMc(CommonConstant.ZERO_COMMON_CONSTANT);
            }
            /* 交易金额上限 */
            if (!StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getAmountLimitMc())) {
                mcCashierCashbackInfo.setAmountLimitMc(MompAmountUtil.getTwoDecimal(cashierCashbackMcInfoBean.getAmountLimitMc()));
            } else {
                mcCashierCashbackInfo.setAmountLimitMc(CommonConstant.ZERO_COMMON_CONSTANT);
            }
            /* 返现金额上限 */
            if (!StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getCashbackLimitMc())) {
                mcCashierCashbackInfo.setCashbackLimitMc(MompAmountUtil.getTwoDecimal(cashierCashbackMcInfoBean.getCashbackLimitMc()));
            } else {
                mcCashierCashbackInfo.setCashbackLimitMc(CommonConstant.ZERO_COMMON_CONSTANT);
            }
            /* 营销方式 */
            if (StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getCashbackMethod())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            } else {
                mcCashierCashbackInfo.setCashbackMethod(cashierCashbackMcInfoBean.getCashbackMethod());
            }
            /* 审批状态-待提交审批状态 */
            mcCashierCashbackInfo.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            mcCashierCashbackInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcCashierCashbackInfo.setCreateTime(globalTimeStamp);
            /* 最后修改人 */
            mcCashierCashbackInfo.setLastOprId(cashierCashbackMcInfoBean.getLastOprId());
            /* 修改时间 */
            mcCashierCashbackInfo.setUpdateTime(cashierCashbackMcInfoBean.getUpdateTime());
            /* 审批拒绝原因 */
            mcCashierCashbackInfo.setAuditRefuseReason(cashierCashbackMcInfoBean.getAuditRefuseReason());
            /* 发布拒绝原因 */
            mcCashierCashbackInfo.setPublishRefuseReason(cashierCashbackMcInfoBean.getPublishRefuseReason());
            /* 备用字段1 */
            mcCashierCashbackInfo.setRemark1(cashierCashbackMcInfoBean.getRemark1());
            /* 备用字段2 */
            mcCashierCashbackInfo.setRemark2(cashierCashbackMcInfoBean.getRemark2());
            /* 备用字段3 */
            mcCashierCashbackInfo.setRemark2(cashierCashbackMcInfoBean.getRemark3());
            /* 备用字段4 */
            mcCashierCashbackInfo.setRemark2(cashierCashbackMcInfoBean.getRemark4());
            /* 备用字段5 */
            mcCashierCashbackInfo.setRemark2(cashierCashbackMcInfoBean.getRemark5());
            /* 创建机构 */
            if (!StringUtil.isNullorEmpty(globalOrgId)) {
                mcCashierCashbackInfo.setCrtOrgId(globalOrgId);
            }
            if (globalMchntFlag.equals(CommonConstant.ONE_COMMON_CONSTANT)) {
                /* 活动发布批量任务状态 */
                mcCashierCashbackInfo.setPublishBatchStatus(CommonConstant.PUBLISH_BATCH_SUCCESS);
            } else {
                /* 活动发布批量任务状态 */
                mcCashierCashbackInfo.setPublishBatchStatus(CommonConstant.PUBLISH_BATCH_INITIAL);
            }
            /* 积分规则数据 */
            mcCashierCashbackInfo.setPointRuleData(cashierCashbackMcInfoBean.getPointRuleData());
        } catch (Exception e) {
            rglog.error("转换营销活动信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }
        return mcCashierCashbackInfo;
    }

    /**
     * 营销活动机构信息数据库实体类和接口实体类数据转换
     *
     * @param mcOrgInfoBean 营销活动机构信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcOrgInfo 营销活动机构信息表
     * @author Jinan Liu
     * @date 2020/4/1 21:11
     */
    private TMMcOrgInfo convertMcOrgInfo(McOrgInfoBean mcOrgInfoBean) {
        TMMcOrgInfo mcOrgInfo = new TMMcOrgInfo();
        try {
            /* 法人机构号 */
            mcOrgInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcOrgInfo.setMcNo(globalMcNo);
            /* 机构编号 */
            mcOrgInfo.setOrgId(mcOrgInfoBean.getOrgId());
            /* 机构层级 */
            mcOrgInfo.setOrgHierarchy(mcOrgInfoBean.getOrgHierarchy());
            /* 机构名称 */
            mcOrgInfo.setOrgName(mcOrgInfoBean.getOrgName());
            /* 创建人 */
            mcOrgInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcOrgInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动机构信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcOrgInfo;
    }

    /**
     * 营销活动商户信息数据库实体类和接口实体类数据转换
     *
     * @param mcMchntInfoBean 营销活动商户信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcMchntInfo 营销活动商户信息表
     * @author Jinan Liu
     * @date 2020/4/1 21:10
     */
    private TMMcMchntInfo convertMcMchntInfo(McMchntInfoBean mcMchntInfoBean) {
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        try {
            /* 法人机构号 */
            mcMchntInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcMchntInfo.setMcNo(globalMcNo);
            /* 商户范围类型 */
            mcMchntInfo.setMchntType(mcMchntInfoBean.getMchntType());
            /* 商户范围号 */
            mcMchntInfo.setMchntNo(mcMchntInfoBean.getMchntNo());
            /* 商户范围名称 */
            mcMchntInfo.setMchntName(mcMchntInfoBean.getMchntName());
            /* 操作类型 */
            mcMchntInfo.setOprType(mcMchntInfoBean.getOprType());
            /* 新增商户标志 */
            mcMchntInfo.setNewMchntFlag(CommonConstant.MCHNT_OLD_FLAG);
            /* 退出标志 */
            mcMchntInfo.setExitFlag(CommonConstant.MC_NOT_EXIT_FLAG);
            /* 达标日期 */
            mcMchntInfo.setQualifiedDate(globalTxnDate);
            /* 创建人 */
            mcMchntInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcMchntInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcMchntInfo;
    }

    /**
     * 营销活动规则信息数据库实体类和接口实体类数据转换
     *
     * @param cashierCashbackRuleInfoBean 收银员返现类活动规则信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcCashierCashbackRuleInfo 收银员返现类活动规则表
     * @author Jinan Liu
     * @date 2020/4/1 21:07
     */
    private TMMcCashierCashbackRuleInfo convertMcRuleInfo(CashierCashbackRuleInfoBean cashierCashbackRuleInfoBean) {

        // 检查上传字段 不能为负数
        checkRuleInfoFieldHasNegativeNumber(cashierCashbackRuleInfoBean);

        TMMcCashierCashbackRuleInfo cashierCashbackRuleInfo = new TMMcCashierCashbackRuleInfo();

        try {
            /* 法人机构号 */
            cashierCashbackRuleInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            cashierCashbackRuleInfo.setMcNo(globalMcNo);
            /* 顺序号  */
            cashierCashbackRuleInfo.setRuleIndex(cashierCashbackRuleInfoBean.getRuleIndex());
            /* 控制下限 */
            cashierCashbackRuleInfo.setCriteriaFloor(MompAmountUtil.getTwoDecimal(cashierCashbackRuleInfoBean.getCriteriaFloor()));
            /* 控制上限 */
            cashierCashbackRuleInfo.setCriteriaCelling(MompAmountUtil.getTwoDecimal(cashierCashbackRuleInfoBean.getCriteriaCelling()));
            /* 返现比例 */
            cashierCashbackRuleInfo.setCashbackRatio(cashierCashbackRuleInfoBean.getCashbackRatio());
            /* 优惠类型 0-现金 1-积分*/
            String discountType = cashierCashbackRuleInfoBean.getDiscountType();
            cashierCashbackRuleInfo.setDiscountType(discountType);
            /* 优惠力度 */
            if (CommonConstant.ZERO_COMMON_CONSTANT.equals(discountType)) {
                cashierCashbackRuleInfo.setDiscount(MompAmountUtil.getTwoDecimal(cashierCashbackRuleInfoBean.getDiscount()));
            } else if (CommonConstant.ONE_COMMON_CONSTANT.equals(discountType)) {
                cashierCashbackRuleInfo.setDiscount(cashierCashbackRuleInfoBean.getDiscount());
            }
            /* 创建人 */
            cashierCashbackRuleInfo.setOprId(globalOprId);
            /* 创建时间 */
            cashierCashbackRuleInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动规则信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return cashierCashbackRuleInfo;
    }

    /**
     * 营销活动支付产品信息数据库实体类和接口实体类数据转换
     *
     * @param mcProductInfoBean 营销活动产品对象
     * @return cc.rengu.igas.momp.common.entity.TMMcProductInfo 营销活动产品信息表
     * @author Jinan Liu
     * @date 2020/4/1 21:06
     */
    private TMMcProductInfo convertMcProductInfo(McProductInfoBean mcProductInfoBean) {
        TMMcProductInfo mcProductInfo = new TMMcProductInfo();
        try {
            /* 法人机构号 */
            mcProductInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcProductInfo.setMcNo(globalMcNo);
            /* 业务产品代码 */
            mcProductInfo.setBizProdCode(mcProductInfoBean.getBizProdCode());
            /* 创建人 */
            mcProductInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcProductInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动支付产品信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcProductInfo;
    }

    /**
     * 新增营销活动信息
     *
     * @param dbsUtil                            数据为操作工具类
     * @param editCashierCashbackMcDetailRequest 收银员返现类活动信息编辑接口请求对象
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/21 18:48
     */
    private void insertAllMcInfoByBank(DbsUtil dbsUtil, EditCashierCashbackMcDetailRequest editCashierCashbackMcDetailRequest) throws Exception {

        /* 营销活动基本信息新增 */
        TMMcCashierCashbackInfo mcCashierCashbackInfo = convertMcInfo(editCashierCashbackMcDetailRequest.getMcInfoObj());
        /** 上传商户文件，活动审批状态修改为中间态 */
        if (merFileFlag) {
            /** 备份当前活动审批状态 */
            flowAuditStatus = mcCashierCashbackInfo.getAuditStatus();
            /* 调整审批状态为任务处理中 */
            mcCashierCashbackInfo.setAuditStatus(AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode());
        }
        insertMoMcInfo(dbsUtil, mcCashierCashbackInfo);
        TMPlatBizTmp tmPlatBizTmp = convertMoMcInfoToTmp(mcCashierCashbackInfo);
        if (merFileFlag) {
            /** 备份当前活动审批状态 */
            flowTmpAuditStatus = tmPlatBizTmp.getAuditStatus();
            /* 调整审批状态为任务处理中 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode());
            auditStatusChangeFlag = true;
        }
        insertTmpMoMcInfo(dbsUtil, tmPlatBizTmp);

        /* 营销活动机构信息新增 */
        List<TMMcOrgInfo> mcOrgInfoList = editCashierCashbackMcDetailRequest.getOrgInfoList().stream().map(this::convertMcOrgInfo).collect(Collectors.toList());
        insertMcOrgInfo(dbsUtil, mcOrgInfoList);
        List<TMPlatBizTmp> tmpOrgList = mcOrgInfoList.stream().map(this::convertMcOrgInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpOrgList);

        /** 判断是否存在文件，存在则创建任务流水 */
        if (merFileFlag) {
            /** 创建定时任务 */
            rglog.info("法人机构<{}>的营销活动<{}>同步创建营销活动任务信息!", globalInstId, globalMcNo);
            insertMcTaskInfoForMerFile(dbsUtil, editCashierCashbackMcDetailRequest.getMrctFilePath());
        } else {
            /* 营销活动商户信息处理 */
            List<TMMcMchntInfo> tmMcMchntInfoList = editCashierCashbackMcDetailRequest.getMchntInfoList().stream().map(this::convertMcMchntInfo).collect(Collectors.toList());
            tmMcMchntInfoList = tmMcMchntInfoList.stream().distinct().collect(Collectors.toList());
            /* 上传商户信息，需要判断商户新增/删除 */
            rglog.info("法人机构<{}>的营销活动<{}>编辑商户/商圈列表，size<{}>", globalInstId, globalMcNo, tmMcMchntInfoList.size());
            //商户列表，增量处理方式
            List<TMMcMchntInfo> mcMchntInfoList = tmMcMchntInfoList.stream().filter(item -> CommonConstant.ZERO_COMMON_CONSTANT.equals(item.getMchntType())).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>编辑商户列表，size<{}>", globalInstId, globalMcNo, mcMchntInfoList.size());

            /* 删除商户列表 */
            List<TMMcMchntInfo> delTmMcMchntList = mcMchntInfoList.stream().filter(item -> OprTypeEnum.DELETE.getOprTypeCode().equals(item.getOprType())).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>删除商户列表，size<{}>", globalInstId, globalMcNo, delTmMcMchntList.size());
            deleteMcMchntInfoList(dbsUtil, delTmMcMchntList);
            List<TMPlatBizTmp> delMcMchntList = delTmMcMchntList.stream().map(this::convertMcMchntInfoToTmp).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>删除商户列表临时表，size<{}>", globalInstId, globalMcNo, delMcMchntList.size());
            deleteMultiMcDetialInfoByBank(dbsUtil, delMcMchntList);

            /* 新增商户列表 */
            List<TMMcMchntInfo> addTmMcMchntList = mcMchntInfoList.stream().filter(item -> OprTypeEnum.INSERT.getOprTypeCode().equals(item.getOprType())).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>保存商户列表，size<{}>", globalInstId, globalMcNo, addTmMcMchntList.size());
            insertMcMchntInfo(dbsUtil, addTmMcMchntList);
            List<TMPlatBizTmp> addTmpMchntList = addTmMcMchntList.stream().map(this::convertMcMchntInfoToTmp).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>保存商户列表临时表，size<{}>", globalInstId, globalMcNo, addTmpMchntList.size());
            insertMultiMcDetialInfoByBank(dbsUtil, addTmpMchntList);

            /* 商圈列表，全量处理方式 */
            List<TMMcMchntInfo> tradeAreatList = tmMcMchntInfoList.stream().filter(item -> CommonConstant.ONE_COMMON_CONSTANT.equals(item.getMchntType())).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>保存商圈列表，size<{}>", globalInstId, globalMcNo, tradeAreatList.size());
            insertMcMchntInfo(dbsUtil, tradeAreatList);
            List<TMPlatBizTmp> tmpMchntList = tradeAreatList.stream().map(this::convertMcMchntInfoToTmp).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>保存商圈列表临时表，size<{}>", globalInstId, globalMcNo, tmpMchntList.size());
            insertMultiMcDetialInfoByBank(dbsUtil, tmpMchntList);
        }

        /* 营销活动规则信息新增 */
        List<TMMcCashierCashbackRuleInfo> cashierCashbackRuleInfoList = editCashierCashbackMcDetailRequest.getRuleInfoList().stream().map(this::convertMcRuleInfo).collect(Collectors.toList());
        insertMcMoRuleInfo(dbsUtil, cashierCashbackRuleInfoList);
        List<TMPlatBizTmp> tmpMoMcRuleList = cashierCashbackRuleInfoList.stream().map(this::convertMoMcRuleInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpMoMcRuleList);

        /* 营销活动产品信息新增 */
        List<TMMcProductInfo> mcProductInfoList = editCashierCashbackMcDetailRequest.getProductInfoList().stream().map(this::convertMcProductInfo).collect(Collectors.toList());
        insertMcProductInfo(dbsUtil, mcProductInfoList);
        List<TMPlatBizTmp> tmpProdList = mcProductInfoList.stream().map(this::convertMcProdInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpProdList);

        /* 积分规则数据	pointRuleData 新增 */
//        String  pointRuleData = editCashierCashbackMcDetailRequest.getMcInfoObj().getPointRuleData();
//        if(null != pointRuleData && !"".equals(pointRuleData)){
//            insertPointRuleDataInfo(dbsUtil, pointRuleData);
//            List<TMPlatBizTmp> tmpPointRuleDataList = convertPointRuleDataInfoToTmp(pointRuleData);
//            insertMultiMcDetialInfoByBank(dbsUtil, tmpPointRuleDataList);
//        }
    }

    /**
     * 提交审批营销活动信息
     *
     * @param editCashierCashbackMcDetailRequest 收银员返现类活动信息编辑接口请求对象
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/4/6 17:43
     */
    private void submitMcInfo(EditCashierCashbackMcDetailRequest editCashierCashbackMcDetailRequest) throws Exception {

        int returnCode = 0;
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();

        rglog.info("提交审批流程开始");

        /* 营销活动信息正式表查询 */
        TMMcCashierCashbackInfo tmMcCashierCashbackInfo = null;
        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
        /* 营销活动信息临时表查询 */
        TMPlatBizTmp platBizTmp = null;
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();

        if (StringUtil.isNullorEmpty(globalMcNo)) {
            rglog.info("上送数据无营销活动编号!");
        } else {
            tmMcCashierCashbackInfo = (TMMcCashierCashbackInfo) mcDetailInfoMapper.selectMcDetailInfo(globalInstId, globalMcNo, TableNameEnum.T_M_MC_CCB_INFO.getTableNameCode());
            platBizTmp = platBizTmpMapper.selectTmpMcInfo(globalInstId, globalMcNo, TableNameEnum.T_M_MC_CCB_INFO.getTableNameCode());
        }

        // 开启数据库事务
        String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MOMP_POOL_NAME);
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        dbsUtil.dbsBeginTransaction();

        if (null == tmMcCashierCashbackInfo && null == platBizTmp) {
            /* 新增提交审批场景，新增数据后直接确认创建

             * 如果营销活动编号不存在，说明是全新的营销活动，需要生成一个营销活动编号，并新增全部数据；
             * 如果营销活动编号存在，说明是接口调用错误，需要返回失败信息；
             */
            if (StringUtil.isNullorEmpty(globalMcNo)) {
                // 生成营销活动编号
                globalMcNo = generateNewMcNo(editCashierCashbackMcDetailRequest.getMcInfoObj());
                if (!StringUtil.isNullorEmpty(globalMcNo)) {
                    rglog.info("新生成的营销活动编号 MC_NO=<{}>", globalMcNo);
                }
                //全部新增流程，插入数据
                rglog.info("提交审批新增流程开始");
                insertAllMcInfoByBank(dbsUtil, editCashierCashbackMcDetailRequest);

            } else {
                /* 如果营销活动编号存在,但是上步没有查询到营销活动,错误 */
                rglog.error("当前营销活动<{}>不可保存数据!", globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespCode(), RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespDesc());
            }
            String auditStatus = AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode();
            String tmpAuditStatus = AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode();
            if (merFileFlag) {
                // 更新临时表除活动信息外其他信息审批状态
                returnCode = platBizTmpMapper.updateTmpMcOtherAuditStatusByPrimaryKey(globalInstId, globalMcNo, TABLE_NAME,
                        AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), tmpAuditStatus, BizStatusEnum.TMP_STATUS.getBizStatusCode(), McStatusEnum.DRAFT.getMcStatusCode());
                if (Database.DBS_SUCCESS != returnCode) {
                    // 更新临时表中营销活动审批状态失败
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                }

                /* 备份活动表、临时表业务数据，任务完成后还原审批状态 */
                JSONObject bizDate = new JSONObject();
                bizDate.put("auditStatus", auditStatus);
                bizDate.put("tmpAuditStatus", tmpAuditStatus);
                rglog.info("交易流水号：<{}>,任务流水号<{}>,switch-2,备份原营销活动审批状态<{}>", traceNo, globalFlowNo, bizDate.toString());
                auditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                tmpAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                /* 更新任务表业务数据信息 */
                updateMcTaskInfoBizDate(dbsUtil, globalInstId, globalMcNo, globalFlowNo, bizDate.toString());

                String oldAuditStatus = AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode();
                if (auditStatusChangeFlag) {
                    oldAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                }
                // 更新临时表活动信息审批状态
                returnCode = platBizTmpMapper.updateTmpMcInfoAuditStatusByPrimaryKey(globalInstId, globalMcNo, TABLE_NAME,
                        oldAuditStatus, tmpAuditStatus, BizStatusEnum.TMP_STATUS.getBizStatusCode(), McStatusEnum.DRAFT.getMcStatusCode());
                if (Database.DBS_SUCCESS != returnCode) {
                    // 更新临时表中营销活动审批状态失败
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                }
                //更新正式表审批状态
                returnCode = mcDetailInfoMapper.updateCashierCashbackMcAuditStatusByPrimaryKeyForTask(globalInstId, globalMcNo, auditStatus);
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新正式表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                }


            } else {
                // 更新临时表审批状态
                returnCode = platBizTmpMapper.updateTmpMcAuditStatusByPrimaryKey(globalInstId, globalMcNo, AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode(), BizStatusEnum.TMP_STATUS.getBizStatusCode(), McStatusEnum.DRAFT.getMcStatusCode());
                if (Database.DBS_SUCCESS != returnCode) {
                    // 更新临时表中营销活动审批状态失败
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                }
                //更新正式表审批状态
                returnCode = mcDetailInfoMapper.updateCashierCashbackMcAuditStatusByPrimaryKey(globalInstId, globalMcNo, AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode());
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新正式表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                }

            }

            //正常结束数据库事务 */
            dbsUtil.dbsEndTransaction(true);

        } else if (null != tmMcCashierCashbackInfo && null != platBizTmp) {
            /* 数据库有历史数据，需要判断历史数据状态 */

            /* 判断活动审批状态，是否存在未完成任务 */
            if (AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode().equals(platBizTmp.getAuditStatus())) {
                /* 不可提交审批状态 */
                rglog.error("定时任务处理中，营销活动是不可提交审批状态,不可提交审批, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespDesc());
            }

            /* 判断营销活动审批状态 */
            if (!AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode().equals(platBizTmp.getAuditStatus()) &&
                    !AuditStatusEnum.NEW_AUDIT_REJECT.getAuditStatusCode().equals(platBizTmp.getAuditStatus()) &&
                    !AuditStatusEnum.MODIFY_AUDIT_REJECT.getAuditStatusCode().equals(platBizTmp.getAuditStatus()) &&
                    !AuditStatusEnum.PUBLISH_AUDIT_REJECT.getAuditStatusCode().equals(platBizTmp.getAuditStatus())) {
                /* 不可提交审批状态 */
                rglog.error("营销活动是不可提交审批状态,不可提交审批, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespDesc());
            }

            /* 判断营销活动状态*/
            if (!McStatusEnum.DRAFT.getMcStatusCode().equals(platBizTmp.getMcStatus()) &&
                    !McStatusEnum.NOT_PUBLISHED.getMcStatusCode().equals(platBizTmp.getMcStatus())) {
                /* 营销活动状态异常，不可提交审批 */
                dbsUtil.dbsEndTransaction(false);
                rglog.error("营销活动状态异常，不可提交审批, MC_STATUS=<{}>, MC_NO=<{}>", platBizTmp.getMcStatus(), globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.WRONG_MC_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_MC_STATUS_TO_SUBMIT_ERROR.getRespDesc());
            } else {
                /* 新增提交审批场景
                 * 如果营销活动编号不存在，说明数据异常，不可提交审批；
                 * 如果营销活动编号存在，说明是正常的新增提交审批场景，可以提交审批；
                 */
                if (StringUtil.isNullorEmpty(globalMcNo)) {
                    /* 全部更新流程，更新数据 */
                    rglog.error("当前营销活动<{}>不可保存数据!", globalMcNo);
                    dbsUtil.dbsEndTransaction(false);
                    throw new BizException(RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespCode(), RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespDesc());
                } else {
                    /* 正式表临时表一起更新,先删除原数据再插入 */
                    updateMcInfoByBank(dbsUtil, editCashierCashbackMcDetailRequest, xmlTreeUtil);
                }

                String tmpMcStatus = platBizTmp.getMcStatus();
                String tmpAuditStatus = platBizTmp.getAuditStatus();
                String tmpBizStatus = platBizTmp.getBizStatus();

                String mcStatus = tmMcCashierCashbackInfo.getMcStatus();

                String newTmpAuditStatus = "";
                String newAuditStatus = "";

                if (AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode().equals(tmpAuditStatus)) {
                    newTmpAuditStatus = AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode();
                    newAuditStatus = AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode();
                } else if (AuditStatusEnum.NEW_AUDIT_REJECT.getAuditStatusCode().equals(tmpAuditStatus) ||
                        AuditStatusEnum.MODIFY_AUDIT_REJECT.getAuditStatusCode().equals(tmpAuditStatus) ||
                        AuditStatusEnum.PUBLISH_AUDIT_REJECT.getAuditStatusCode().equals(tmpAuditStatus)) {
                    newTmpAuditStatus = AuditStatusEnum.MODIFY_AUDIT_PROCESSING.getAuditStatusCode();
                    newAuditStatus = AuditStatusEnum.MODIFY_AUDIT_PROCESSING.getAuditStatusCode();
                } else {
                    rglog.error("营销活动临时表状态异常，不可提交审批, MC_STATUS=<{}>, MC_NO=<{}>!", tmpAuditStatus, globalMcNo);
                    dbsUtil.dbsEndTransaction(false);
                    throw new BizException(RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespCode(), RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespDesc());
                }


                if (merFileFlag) {
                    /* 更新临时表除活动信息外其他信息审批状态 */
                    returnCode = platBizTmpMapper.updateTmpMcOtherStatusByMcNoAndAuditStatus(globalInstId, globalMcNo, TABLE_NAME,
                            tmpBizStatus, tmpMcStatus, newTmpAuditStatus, AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), globalOprId, globalTimeStamp);
                    if (Database.DBS_SUCCESS != returnCode) {
                        /* 更新临时表中营销活动审批状态失败 */
                        dbsUtil.dbsEndTransaction(false);
                        rglog.error("更新临时表中营销活动其他信息审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                        throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                    }

                    /* 备份活动表、临时表业务数据，任务完成后还原审批状态 */
                    JSONObject bizDate = new JSONObject();
                    bizDate.put("auditStatus", newAuditStatus);
                    bizDate.put("tmpAuditStatus", newTmpAuditStatus);
                    rglog.info("交易流水号：<{}>,任务流水号<{}>,switch-3,备份原营销活动审批状态<{}>", traceNo, globalFlowNo, bizDate.toString());
                    newAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                    newTmpAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                    /* 更新任务表业务数据信息 */
                    updateMcTaskInfoBizDate(dbsUtil, globalInstId, globalMcNo, globalFlowNo, bizDate.toString());
                    String oldAuditStatus = AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode();
                    if (auditStatusChangeFlag) {
                        oldAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                    }

                    /* 更新临时表活动信息审批状态 */
                    returnCode = platBizTmpMapper.updateTmpMcInfoStatusByMcNoAndAuditStatus(globalInstId, globalMcNo, TABLE_NAME,
                            tmpBizStatus, tmpMcStatus, newTmpAuditStatus, oldAuditStatus, globalOprId, globalTimeStamp);
                    if (Database.DBS_SUCCESS != returnCode) {
                        /* 更新临时表中营销活动审批状态失败 */
                        dbsUtil.dbsEndTransaction(false);
                        rglog.error("更新临时表中营销活动活动信息审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                        throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                    }

                } else {
                    /* 更新临时表审批状态 */
                    returnCode = platBizTmpMapper.updateTmpMcAllStatusByMcNoAndAuditStatus(globalInstId, globalMcNo, tmpBizStatus, tmpMcStatus, newTmpAuditStatus, AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), globalOprId, globalTimeStamp);
                    if (Database.DBS_SUCCESS != returnCode) {
                        /* 更新临时表中营销活动审批状态失败 */
                        dbsUtil.dbsEndTransaction(false);
                        rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                        throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                    }
                }
                /* 更新正式表审批状态 */
                TMMcCashierCashbackInfo TMMcCashierCashbackInfo1 = new TMMcCashierCashbackInfo();
                TMMcCashierCashbackInfo1.setInstId(globalInstId);
                TMMcCashierCashbackInfo1.setMcNo(globalMcNo);
                TMMcCashierCashbackInfo1.setMcStatus(mcStatus);
                TMMcCashierCashbackInfo1.setAuditStatus(newAuditStatus);
                TMMcCashierCashbackInfo1.setLastOprId(globalOprId);
                TMMcCashierCashbackInfo1.setUpdateTime(globalTimeStamp);

                returnCode = mcDetailInfoMapper.updateMcStatusForPublishing(TMMcCashierCashbackInfo1, TABLE_NAME);
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新正式表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                }
            }

            /* 正常结束数据库事务 */
            dbsUtil.dbsEndTransaction(true);

        } else {
            /* 异常结束数据库事务 */
            rglog.error("查询营销活动信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 更新营销活动信息
     * 修改草稿流程使用
     *
     * @param xmlTreeUtil                        内部XML树
     * @param editCashierCashbackMcDetailRequest 收银员返现类活动信息编辑接口请求对象
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/4/2 00:13
     */
    private void updateAllDraftMcInfoByBank(XmlTreeUtil xmlTreeUtil, EditCashierCashbackMcDetailRequest editCashierCashbackMcDetailRequest) throws Exception {
        /* 开启数据库事务 */
        String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MOMP_POOL_NAME);
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        dbsUtil.dbsBeginTransaction();

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();
        tmPlatBizTmp.setInstId(globalInstId);
        tmPlatBizTmp.setMcNo(globalMcNo);
        tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
        tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
        tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());

        /* 删除指定营销活动编号的所有草稿状态的数据数据 */
        deleteAllDraftMcInfoByBank(dbsUtil);
        /* 处理因机构变更导致需要删除的商户数据 */
        delMchntListByDelOrgList(dbsUtil, editCashierCashbackMcDetailRequest.getOrgInfoList());

        deleteCashierCashbackMcInfo(dbsUtil);
        deleteMcOrgInfo(dbsUtil);
        /* 1.商户信息上送方式调整为只上送本次调整的商户列表，新增/删除商户信息，2.商圈列表全量删除*/
        //deleteMcMchntInfo(dbsUtil);
        deleteMcMchntAreat(dbsUtil, CommonConstant.ONE_COMMON_CONSTANT);
        deleteMcMoRuleInfo(dbsUtil);
        deleteMcProductInfo(dbsUtil);
//        deletePointRuleDataInfo(dbsUtil,xmlTreeUtil);

        insertAllMcInfoByBank(dbsUtil, editCashierCashbackMcDetailRequest);

        /* 正常结束数据库事务 */
        dbsUtil.dbsEndTransaction(true);
    }

    /**
     * 生成营销活动编号
     *
     * @param cashierCashbackMcInfoBean 收银员返现活动基本信息对象
     * @return java.lang.String
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/21 14:57
     */
    private String generateNewMcNo(CashierCashbackMcInfoBean cashierCashbackMcInfoBean) throws Exception {

        // MC+2位营销活动类型+1位出资方+8位活动起始日期+8位活动截止日期+11位sequence
        MompSequenceMapper mompSequenceMapper = new MompSequenceMapperImpl();

        String mcNoSuffix = mompSequenceMapper.getMompNextMaNoSeq();
        //收银员返现活动均为银行出资
        return "MC" + cashierCashbackMcInfoBean.getMcType() + CommonConstant.SPONSOR_BANK + cashierCashbackMcInfoBean.getMcStartDate() + cashierCashbackMcInfoBean.getMcEndDate() + mcNoSuffix;
    }


    /**
     * 插入收银员返现类活动基本信息
     *
     * @param dbsUtil               数据库操作工具类
     * @param mcCashierCashbackInfo 收银员返现类活动信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/21 16:35
     */
    private void insertMoMcInfo(DbsUtil dbsUtil, TMMcCashierCashbackInfo mcCashierCashbackInfo) throws Exception {

        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
        int returnCode = mcDetailInfoMapper.insertCashierCashbackMcInfo(mcCashierCashbackInfo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 将收银员返现类活动基本信息插入临时表中
     *
     * @param dbsUtil      数据库操作工具类
     * @param tmPlatBizTmp 业务数据临时表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/22 15:39
     */
    private void insertTmpMoMcInfo(DbsUtil dbsUtil, TMPlatBizTmp tmPlatBizTmp) throws Exception {

        /* 数据入库 */
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        int returnCode = platBizTmpMapper.insertMcInfoByBank(tmPlatBizTmp);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 收银员返现类活动信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param mcCashierCashbackInfo 收银员返现类活动信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author Jinan Liu
     * @date 2020/5/22 11:49
     */
    private TMPlatBizTmp convertMoMcInfoToTmp(TMMcCashierCashbackInfo mcCashierCashbackInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();
        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(mcCashierCashbackInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(mcCashierCashbackInfo.getMcNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_CCB_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_CCB_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcCashierCashbackInfoTmpBizData1(mcCashierCashbackInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动机构信息表
     *
     * @param dbsUtil       数据库操作工具类
     * @param mcOrgInfoList 营销活动机构信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/21 16:38
     */
    private void insertMcOrgInfo(DbsUtil dbsUtil, List<TMMcOrgInfo> mcOrgInfoList) throws Exception {

        McOrgInfoMapper mcOrgInfoMapper = new McOrgInfoMapperImpl();
        int returnCode = mcOrgInfoMapper.insertMcOrgInfoListByBank(mcOrgInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动机构信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 将营销活动机构信息插入临时表中
     *
     * @param dbsUtil          数据库操作工具类
     * @param tmPlatBizTmpList 业务数据临时表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/28 22:17
     */
    private void insertMultiMcDetialInfoByBank(DbsUtil dbsUtil, List<TMPlatBizTmp> tmPlatBizTmpList) throws Exception {

        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        int returnCode = platBizTmpMapper.insertMultiMcDetialInfoByBank(tmPlatBizTmpList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动机构信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 将积分规则数据信息插入临时表中
     *
     * @param dbsUtil          数据库操作工具类
     * @param tmPlatBizTmpList 业务数据临时表
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/22
     */
    private void insertPointRuleData(DbsUtil dbsUtil, List<TMPlatBizTmp> tmPlatBizTmpList) throws Exception {

        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        int returnCode = platBizTmpMapper.insertMultiMcDetialInfoByBank(tmPlatBizTmpList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增积分规则数据失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动机构信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcOrgInfo 营销活动机构信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author Jinan Liu
     * @date 2020/5/28 22:12
     */
    private TMPlatBizTmp convertMcOrgInfoToTmp(TMMcOrgInfo tmMcOrgInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcOrgInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcOrgInfo.getMcNo());
            /* 机构编号 */
            tmPlatBizTmp.setOrgId(tmMcOrgInfo.getOrgId());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_ORG_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_ORG_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcOrgInfoTmpBizData1(tmMcOrgInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动商户信息
     *
     * @param dbsUtil         数据库操作工具类
     * @param mcMchntInfoList 营销活动商户信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/21 18:05
     */
    private void insertMcMchntInfo(DbsUtil dbsUtil, List<TMMcMchntInfo> mcMchntInfoList) throws Exception {
        if (mcMchntInfoList != null && !mcMchntInfoList.isEmpty()) {
            rglog.info("编辑营销活动新增商户信息列表size<{}>", mcMchntInfoList.size());
            McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
            int returnCode = mcMchntInfoMapper.insertMcMchntInfoListByBank(mcMchntInfoList);
            if (Database.DBS_SUCCESS != returnCode) {
                /* 异常结束数据库事务 */
                rglog.error("新增营销活动商户信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
            }
        } else {
            rglog.info("编辑营销活动新增商户信息列表无数据，MC_NO=<{}>", globalMcNo);
        }
    }

    /**
     * 营销活动商户信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcMchntInfo 营销活动商户信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author Jinan Liu
     * @date 2020/5/28 22:26
     */
    private TMPlatBizTmp convertMcMchntInfoToTmp(TMMcMchntInfo tmMcMchntInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcMchntInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcMchntInfo.getMcNo());
            /* 商户编号 */
            tmPlatBizTmp.setMchntNo(tmMcMchntInfo.getMchntNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameCode());
            /* 操作  默认新增改为获取请求报文中操作类型 */
            if (StringUtil.isNullorEmpty(tmMcMchntInfo.getOprType())) {
                tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            } else {
                tmPlatBizTmp.setBizOpr(tmMcMchntInfo.getOprType());
            }
            /* 新增商户标志 */
            tmMcMchntInfo.setNewMchntFlag(CommonConstant.MCHNT_OLD_FLAG);
            /* 退出标志 */
            tmMcMchntInfo.setExitFlag(CommonConstant.MC_NOT_EXIT_FLAG);
            /* 达标日期 */
            tmMcMchntInfo.setQualifiedDate(globalTxnDate);
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcMchntInfoTmpBizData1(tmMcMchntInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);
            /* 商户范围类型 */
            tmPlatBizTmp.setRemark1(tmMcMchntInfo.getMchntType());

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }


    /**
     * 插入收银员返现类营销活动规则信息
     *
     * @param dbsUtil                     数据库操作工具类
     * @param cashierCashbackRuleInfoList 收银员返现类活动规则表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/21 18:15
     */
    private void insertMcMoRuleInfo(DbsUtil dbsUtil, List<TMMcCashierCashbackRuleInfo> cashierCashbackRuleInfoList) throws Exception {

        McRuleInfoMapper mcRuleInfoMapper = new McRuleInfoMapperImpl();//insertMoneyOffRuleInfoListByBank
        int returnCode = mcRuleInfoMapper.insertCashierCashbackRuleInfoListByBank(cashierCashbackRuleInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动收银员返现类规则信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动规则信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcCashierCashbackRuleInfo 收银员返现类活动规则表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author Jinan Liu
     * @date 2020/5/28 22:49
     */
    private TMPlatBizTmp convertMoMcRuleInfoToTmp(TMMcCashierCashbackRuleInfo tmMcCashierCashbackRuleInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcCashierCashbackRuleInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcCashierCashbackRuleInfo.getMcNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_CCB_RULE_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_CCB_RULE_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packCashierCashbackRuleInfoTmpBizData1(tmMcCashierCashbackRuleInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动产品信息
     *
     * @param dbsUtil           数据库操作工具类
     * @param mcProductInfoList 营销活动产品信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/21 18:08
     */
    private void insertMcProductInfo(DbsUtil dbsUtil, List<TMMcProductInfo> mcProductInfoList) throws Exception {

        McProductInfoMapper mcProductInfoMapper = new McProductInfoMapperImpl();
        int returnCode = mcProductInfoMapper.insertMcProductInfoListByBank(mcProductInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动产品信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 插入积分规则数据信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/22 16"28
     */
    private void insertPointRuleDataInfo(DbsUtil dbsUtil, String PointRuleData) throws Exception {
        MompSysParamMapper mompSysParamMapper = new MompSysParamMapperImpl();
        SysParam sysParam = new SysParam();
        sysParam.setInstId(globalInstId);
        sysParam.setParamType("MC_BONUS_POINT_CASHBACK_RULE_VALUE");
        sysParam.setParamKey(globalMcNo);
        sysParam.setParamValue(PointRuleData);
        sysParam.setParamStatus("Y");
        sysParam.setCreateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
        sysParam.setUpdateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
        sysParam.setParamDesc("收银员返现积分规则");
        int returnCode = mompSysParamMapper.insertSysParam(sysParam);

        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增积分规则数据信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动产品信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcProductInfo 营销活动产品信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author Jinan Liu
     * @date 2020/5/28 22:49
     */
    private TMPlatBizTmp convertMcProdInfoToTmp(TMMcProductInfo tmMcProductInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcProductInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcProductInfo.getMcNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_PROD_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_PROD_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcProdInfoTmpBizData1(tmMcProductInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 积分规则数据转换
     * 正式表数据转换为临时表数据
     *
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author liujinan
     * @date 2020/6/22
     */
    private List<TMPlatBizTmp> convertPointRuleDataInfoToTmp(String pointRuleData) {

        List<TMPlatBizTmp> tmPlatBizTmpList = new ArrayList<>();
        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(globalInstId);
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(globalMcNo);
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_P_SYS_PARAM.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_P_SYS_PARAM.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(pointRuleData);
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            tmPlatBizTmpList.add(tmPlatBizTmp);

            return tmPlatBizTmpList;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 删除收银员返现类活动基本信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/21 16:35
     */
    private void deleteCashierCashbackMcInfo(DbsUtil dbsUtil) throws Exception {

        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
        int returnCode = mcDetailInfoMapper.deleteCashierCashbackMcInfo(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动机构信息表
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/21 16:38
     */
    private void deleteMcOrgInfo(DbsUtil dbsUtil) throws Exception {

        McOrgInfoMapper mcOrgInfoMapper = new McOrgInfoMapperImpl();
        int returnCode = mcOrgInfoMapper.deleteMcOrgInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动机构信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动商户信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/21 18:05
     */
    private void deleteMcMchntInfo(DbsUtil dbsUtil) throws Exception {

        McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
        int returnCode = mcMchntInfoMapper.deleteMcMchntInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动商户信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动商户/商圈信息
     *
     * @param dbsUtil
     * @param mchntType 商户类型0商户1商圈
     * @throws Exception
     */
    private void deleteMcMchntAreat(DbsUtil dbsUtil, String mchntType) throws Exception {
        //TODO 需要确认是否确保存在数据，如无数据delete是否会报错
        rglog.info("TODO 需要确认是否确保存在数据，如无数据delete是否会报错");
        McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
        int returnCode = mcMchntInfoMapper.deleteMchntInfoByType(globalInstId, globalMcNo, mchntType);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动商户/商圈信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>, MCHNT_TYPE=<{}>", returnCode, globalInstId, globalMcNo, mchntType);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动指定商户信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author liujinan
     * @since 2020/4/12 16:05
     */
    private void deleteMcMchntInfoList(DbsUtil dbsUtil, List<TMMcMchntInfo> mcMchntInfoList) throws Exception {
        if (!mcMchntInfoList.isEmpty()) {
            rglog.info("编辑营销活动删除商户信息列表size<{}>", mcMchntInfoList.size());
            McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
            int returnCode = mcMchntInfoMapper.deleteMcMchntInfoList(globalInstId, globalMcNo, mcMchntInfoList);
            if (Database.DBS_SUCCESS != returnCode) {
                /* 异常结束数据库事务 */
                rglog.error("删除营销活动商户信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
            }
        } else {
            rglog.info("编辑营销活动删除商户信息列表无数据，MC_NO=<{}>", globalMcNo);
        }
    }

    /**
     * 删除营销活动收银员返现类规则信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/21 18:15
     */
    private void deleteMcMoRuleInfo(DbsUtil dbsUtil) throws Exception {
        McRuleInfoMapper mcRuleInfoMapper = new McRuleInfoMapperImpl();//deleteMoneyOffRuleInfoListByBank
        int returnCode = mcRuleInfoMapper.deleteCashierCashbackRuleInfoListByMcNo(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动收银员返现类规则信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动产品信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/21 18:08
     */
    private void deleteMcProductInfo(DbsUtil dbsUtil) throws Exception {
        McProductInfoMapper mcProductInfoMapper = new McProductInfoMapperImpl();
        int returnCode = mcProductInfoMapper.deleteMcProductInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动产品信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除指定营销活动编号的所有草稿状态的数据数据
     * 保留商户临时数据
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/28 23:12
     */
    private void deleteAllDraftMcInfoByBank(DbsUtil dbsUtil) throws Exception {

        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        int returnCode = platBizTmpMapper.deleteTmpMcDataRetainMchntListByMcNo(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            // 异常结束数据库事务
            rglog.error("删除草稿状态营销活动临时表数据失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动积分规则信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/6/23
     */
    private void deletePointRuleDataInfo(DbsUtil dbsUtil, XmlTreeUtil xmlTreeUtil) throws Exception {
        //开启oltp数据库事务
        /* 开启数据库事务 */
        String dbPoolNames = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.OLTP_POOL_NAME);
        String corporations = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporations && !corporations.isEmpty()) {
            String dbPoolCashNode = corporations.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolNames = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.OLTP_POOL_NAME);
        }
        DbsUtil dbsUtils = new DbsUtil(dbPoolNames);
        dbsUtils.dbsBeginTransaction();
        MompSysParamMapper mompSysParamMapper = new MompSysParamMapperImpl();
        //参数类型
        String paramType = "MC_BONUS_POINT_CASHBACK_RULE_VALUE";
        //参数键值
        String paramKey = globalMcNo;
        int returnCode = mompSysParamMapper.deletePointRuleDataInfo(globalInstId, paramType, paramKey);
        if (Database.DBS_SUCCESS != returnCode && Database.DBS_NOT_FOUND != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动积分规则信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtils.dbsEndTransaction(false);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 保存数据流程
     *
     * @param xmlTreeUtil                        内部XML树
     * @param editCashierCashbackMcDetailRequest 收银员返现营销活动信息编辑接口请求对象
     * @throws Exception 异常信息
     * @author liujinan
     * @since 2020-07-06 9:50
     */
    private void saveAllMcInfoByBank(XmlTreeUtil xmlTreeUtil, EditCashierCashbackMcDetailRequest editCashierCashbackMcDetailRequest) throws Exception {

        int returnCode;
        /* 营销活动信息正式表查询 */
        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
        TMMcCashierCashbackInfo tmMcCashierCashbackInfo = (TMMcCashierCashbackInfo) mcDetailInfoMapper.selectMcDetailInfo(globalInstId, globalMcNo, TABLE_NAME);
        if (null == tmMcCashierCashbackInfo) {
            rglog.error("法人机构<{}>的营销活动<{}>的信息不存在!");
            throw new BizException(RespCodeEnum.GET_AGENT_PROFIT_SHARING_MC_DETAIL_ERROR.getRespCode(), RespCodeEnum.GET_AGENT_PROFIT_SHARING_MC_DETAIL_ERROR.getRespDesc());
        }

        /* 营销活动信息临时表查询 */
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        TMPlatBizTmp tmPlatBizTmp = platBizTmpMapper.selectTmpMcInfo(globalInstId, globalMcNo, TABLE_NAME);
        if (null == tmPlatBizTmp) {
            rglog.error("法人机构<{}>的营销活动<{}>的信息不存在!");
            throw new BizException(RespCodeEnum.GET_AGENT_PROFIT_SHARING_MC_DETAIL_ERROR.getRespCode(), RespCodeEnum.GET_AGENT_PROFIT_SHARING_MC_DETAIL_ERROR.getRespDesc());
        }

        /* 数据库有历史数据,需要判断历史数据状态 */

        /* 判断营销活动是否存在进行中跑批任务 */
        if (AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode().equals(tmMcCashierCashbackInfo.getAuditStatus())) {
            /* 营销活动审批状态异常，不可保存数据 */
            rglog.error("法人机构<{}>的营销活动<{}>的审批状态<{}>，存在跑批任务，不可保存数据!", globalInstId, globalMcNo, tmMcCashierCashbackInfo.getAuditStatus());
            throw new BizException(RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespDesc());
        }

        /* 判断营销活动审批状态 */
        if (!AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode().equals(tmPlatBizTmp.getAuditStatus()) &&
                !AuditStatusEnum.NEW_AUDIT_REJECT.getAuditStatusCode().equals(tmPlatBizTmp.getAuditStatus()) &&
                !AuditStatusEnum.MODIFY_AUDIT_REJECT.getAuditStatusCode().equals(tmPlatBizTmp.getAuditStatus()) &&
                !AuditStatusEnum.PUBLISH_AUDIT_REJECT.getAuditStatusCode().equals(tmPlatBizTmp.getAuditStatus())) {
            /* 营销活动审批状态异常,不可保存数据 */
            rglog.error("法人机构<{}>的营销活动<{}>的审批状态<{}>异常,不可保存数据!", globalInstId, globalMcNo, tmPlatBizTmp.getAuditStatus());
            throw new BizException(RespCodeEnum.WRONG_AUDIT_STATUS_TO_SAVE_ERROR.getRespCode(), RespCodeEnum.WRONG_AUDIT_STATUS_TO_SAVE_ERROR.getRespDesc());
        }

        /* 开启数据库事务 */
        String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MOMP_POOL_NAME);
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        dbsUtil.dbsBeginTransaction();

        String auditStatus = tmMcCashierCashbackInfo.getAuditStatus();
        String mcStatus = tmMcCashierCashbackInfo.getMcStatus();

        if (McStatusEnum.PROGRESSING.getMcStatusCode().equals(mcStatus)) {
            /* 正式表营销活动状态是进行中,不允许保存草稿 */
            rglog.error("法人机构<{}>的营销活动<{}>的营销活动状态<{}>异常,不可保存数据!", globalInstId, globalMcNo, tmPlatBizTmp.getAuditStatus());
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.WRONG_MC_STATUS_TO_SAVE_ERROR.getRespCode(), RespCodeEnum.WRONG_MC_STATUS_TO_SAVE_ERROR.getRespDesc());
        } else {
            /* 正式表营销活动状态不是进行中,正式表临时表一起更新,先删除原数据再插入 */
            updateMcInfoByBank(dbsUtil, editCashierCashbackMcDetailRequest, xmlTreeUtil);

            if (merFileFlag) {
                /* 更新临时表除活动信息外其他信息审批状态 */
                returnCode = platBizTmpMapper.updateTmpMcOtherInfoByMcNoAndAuditStatus(globalInstId, globalMcNo, TABLE_NAME,
                        tmPlatBizTmp, AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), globalOprId, globalTimeStamp);
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新临时表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动其他信息审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                }
                /* 备份活动表、临时表业务数据，任务完成后还原审批状态 */
                JSONObject bizDate = new JSONObject();
                bizDate.put("auditStatus", auditStatus);
                bizDate.put("tmpAuditStatus", tmPlatBizTmp.getAuditStatus());
                rglog.info("交易流水号：<{}>,任务流水号<{}>,switch-1,备份原营销活动审批状态<{}>", traceNo, globalFlowNo, bizDate.toString());
                auditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode());
                /* 更新任务表业务数据信息 */
                updateMcTaskInfoBizDate(dbsUtil, globalInstId, globalMcNo, globalFlowNo, bizDate.toString());
                String oldAuditStatus = AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode();
                if (auditStatusChangeFlag) {
                    oldAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                }

                /* 更新临时表活动信息审批状态 */
                returnCode = platBizTmpMapper.updateTmpMcCCBInfoByMcNoAndAuditStatus(globalInstId, globalMcNo, TABLE_NAME,
                        tmPlatBizTmp, oldAuditStatus, globalOprId, globalTimeStamp);
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新临时表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动活动信息审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                }
            } else {
                /* 更新临时表审批状态 */
                returnCode = platBizTmpMapper.updateTmpMcInfoByMcNoAndAuditStatus(globalInstId, globalMcNo, tmPlatBizTmp,
                        AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), globalOprId, globalTimeStamp);
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新临时表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                }
            }



            /* 更新正式表审批状态 */
            TMMcCashierCashbackInfo tmMcCashierCashbackInfo1 = new TMMcCashierCashbackInfo();
            tmMcCashierCashbackInfo1.setInstId(globalInstId);
            tmMcCashierCashbackInfo1.setMcNo(globalMcNo);
            tmMcCashierCashbackInfo1.setMcStatus(mcStatus);
            tmMcCashierCashbackInfo1.setAuditStatus(auditStatus);
            tmMcCashierCashbackInfo1.setLastOprId(globalOprId);
            tmMcCashierCashbackInfo1.setUpdateTime(globalTimeStamp);

            returnCode = mcDetailInfoMapper.updateMcStatusForPublishing(tmMcCashierCashbackInfo1, TABLE_NAME);
            if (Database.DBS_SUCCESS != returnCode) {
                /* 更新正式表中营销活动审批状态失败 */
                dbsUtil.dbsEndTransaction(false);
                rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
            }
        }
        /* 正常结束数据库事务 */
        dbsUtil.dbsEndTransaction(true);
    }

    /**
     * 更新营销活动信息
     * 进行保存的时候使用(可能是草稿的保存,也可能是被拒绝的再次修改后的保存)
     *
     * @param editCashierCashbackMcDetailRequest 收银员返现类营销活动信息编辑接口请求对象
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/7/6 9:50
     */
    private void updateMcInfoByBank(DbsUtil dbsUtil, EditCashierCashbackMcDetailRequest editCashierCashbackMcDetailRequest, XmlTreeUtil xmlTreeUtil) throws Exception {

        //删除指定营销活动编号的所有草稿状态的数据
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        int returnCode = platBizTmpMapper.deleteTmpMcDataByMcNo(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 删除临时表数据失败 */
            dbsUtil.dbsEndTransaction(false);
            rglog.error("删除临时表中营销活动各信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            throw new BizException(RespCodeEnum.DELETE_TMP_MC_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_TMP_MC_DATA_ERROR.getRespDesc());
        }

        //删除正式表数据
        deleteCashierCashbackMcInfo(dbsUtil);
        /* 保留商户数据，删除商圈数据*/
        //deleteMcMchntInfo(dbsUtil);
        deleteMcMchntAreat(dbsUtil, CommonConstant.ONE_COMMON_CONSTANT);
        /* 处理因机构变更需要清除的商户数据 */
        delMchntListByDelOrgList(dbsUtil, editCashierCashbackMcDetailRequest.getOrgInfoList());

        deleteMcOrgInfo(dbsUtil);
        deleteMcMoRuleInfo(dbsUtil);
        deleteMcProductInfo(dbsUtil);
//        deletePointRuleDataInfo(dbsUtil,xmlTreeUtil);

        //重新插入正式表和临时表数据
        insertAllMcInfoByBank(dbsUtil, editCashierCashbackMcDetailRequest);
    }

    /**
     * 校验接口上送的商户信息和机构信息是否匹配
     *
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/7/14 14:00
     */
    private void checkMchntAndOrgInfo(EditCashierCashbackMcDetailRequest editCashierCashbackMcDetailRequest) throws Exception {

        traceNo = editCashierCashbackMcDetailRequest.getHeader().getTraceNo();

        List<McOrgInfoBean> orgInfoList = editCashierCashbackMcDetailRequest.getOrgInfoList();
        List<McMchntInfoBean> mchntInfoList = editCashierCashbackMcDetailRequest.getMchntInfoList();

        if (null == orgInfoList || orgInfoList.isEmpty()) {
            rglog.error("交易流水号：<{}>, 接口请求上送的营销活动机构信息为空", traceNo);
            throw new BizException(RespCodeEnum.GET_MC_ORG_INFO_ERROR.getRespCode(), RespCodeEnum.GET_MC_ORG_INFO_ERROR.getRespDesc());
        }
        if (merFileFlag) {
            rglog.info("交易流水号：<{}>, 接口请求上送的营销活动商户文件路径：<{}>，暂不校验商户及机构是否匹配，流程继续...", traceNo, editCashierCashbackMcDetailRequest.getMrctFilePath());
        } else {
            if (null == mchntInfoList || mchntInfoList.isEmpty()) {
                rglog.info("交易流水号：<{}>, 接口请求上送的营销活动商户信息为空，不校验商户及机构是否匹配，流程继续...", traceNo);
            } else {
                rglog.info("交易流水号：<{}>, 接口请求上送的营销活动商户信息不为空，校验商户及机构是否匹配，流程继续...", traceNo);
                List<String> mchntRealOrgList = new ArrayList<>();
                String mchntType, mchntNo;
                MchntInfoMapper mchntInfoMapper = new MchntInfoMapperImpl();
                TBTradeAreaInfoMapper tbTradeAreaInfoMapperImpl = new TBTradeAreaInfoMapperImpl();
                int maxSize = mchntInfoList.size();
                for (int i = 0; i < maxSize; i++) {
                    McMchntInfoBean mcMchntInfoBean = mchntInfoList.get(i);
                    //商户类型
                    mchntType = mcMchntInfoBean.getMchntType();
                    //商户范围号
                    mchntNo = mcMchntInfoBean.getMchntNo();

                    if (CommonConstant.ZERO_COMMON_CONSTANT.equals(mchntType)) {
                        rglog.info("交易流水号：<{}>, 查询商户<{}>信息开始...", traceNo, mchntNo);
                        String oprType = mcMchntInfoBean.getOprType();
                        if (StringUtil.isNullorEmpty(oprType)) {
                            rglog.error("交易流水号：<{}>, 商户列表数据<{}>操作类型<{}>节点未上送！", traceNo, mchntNo, oprType);
                            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc() + ",商户号" + mchntNo);
                        }

                        //查询商户基本信息
                        TBMchntBaseInfo tbMchntBaseInfo = mchntInfoMapper.selectMchntBaseInfoByMchntNo(globalInstId, mchntNo);
                        if (null == tbMchntBaseInfo) {
                            rglog.error("交易流水号：<{}>, 商户<{}>信息查询异常！", traceNo, mchntNo);
                            throw new BizException(RespCodeEnum.GET_MCHNT_BASE_INFO_ERROR_BY_FORMAL.getRespCode(), RespCodeEnum.GET_MCHNT_BASE_INFO_ERROR_BY_FORMAL.getRespDesc() + ",商户号" + mchntNo);
                        }
                        /** 存量营销活动筛选上传的商户列表，去除oprType=I已存在的商户、去除oprType=D不存在的商户 */
                        if (!StringUtil.isNullorEmpty(globalMcNo)) {
                            rglog.info("校验接口上送的新增/删除商户列表报文是否冗余");
                            McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
                            TMMcMchntInfo mchntInfo = mcMchntInfoMapper.selectTMMcMchntInfoByPrimaryKey(globalInstId, globalMcNo, mchntNo);
                            if (OprTypeEnum.INSERT.getOprTypeCode().equals(oprType)) {
                                if (null != mchntInfo) {
                                    rglog.info("交易流水号：<{}>, 商户列表数据<{}>新增操作校验不通过，该商户已存在，跳过该商户继续流程！", traceNo, mchntNo);
                                    mchntInfoList.remove(mcMchntInfoBean);
                                    maxSize--;
                                    i--;
                                    continue;
                                }
                            } else if (OprTypeEnum.DELETE.getOprTypeCode().equals(oprType)) {
                                if (null == mchntInfo) {
                                    rglog.info("交易流水号：<{}>, 商户列表数据<{}>删除操作校验不通过，该商户不存在无法删除，跳过该商户继续流程！", traceNo, mchntNo);
                                    mchntInfoList.remove(mcMchntInfoBean);
                                    maxSize--;
                                    i--;
                                    continue;
                                }
                            } else {
                                rglog.error("交易流水号：<{}>, 商户列表数据<{}>操作类型<{}>节点值上送错误！", traceNo, mchntNo, oprType);
                                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc() + ",商户号" + mchntNo + "操作类型节点值上送错误");
                            }
                        }
                        mchntRealOrgList.add(tbMchntBaseInfo.getSignInstId());

                    } else if (CommonConstant.ONE_COMMON_CONSTANT.equals(mchntType)) {
                        rglog.info("交易流水号：<{}>, 查询商圈<{}>信息开始...", traceNo, mchntNo);
                        //查询商圈基本信息
                        TBTradeAreatInfo TBTradeAreatInfo = tbTradeAreaInfoMapperImpl.selectTradeAreaInfoByTradeAreaCode(globalInstId, mchntNo);
                        if (null == TBTradeAreatInfo) {
                            rglog.error("交易流水号：<{}>, 商圈<{}>信息查询异常！", traceNo, mchntNo);
                            throw new BizException(RespCodeEnum.GET_MCHNT_BASE_INFO_ERROR_BY_FORMAL.getRespCode(), RespCodeEnum.GET_MCHNT_BASE_INFO_ERROR_BY_FORMAL.getRespDesc() + ",商圈号" + mchntNo);
                        }
                        mchntRealOrgList.add(TBTradeAreatInfo.getBelongInstId());
                    } else {
                        rglog.error("交易流水号：<{}>, 接口请求上送的商户类型错误...", traceNo);
                        throw new BizException(RespCodeEnum.WRONG_MC_MCHNTTYPE.getRespCode(), RespCodeEnum.WRONG_MC_MCHNTTYPE.getRespDesc());
                    }
                }

                //对请求上送的商户所属的机构进行去重处理
                mchntRealOrgList = mchntRealOrgList.stream().distinct().collect(Collectors.toList());

                //处理接口请求上送的机构信息
                List<String> requestOrgIdList = orgInfoList.stream().map(item -> item.getOrgId()).collect(Collectors.toList());
                //对请求上送的机构进行去重处理
                requestOrgIdList = requestOrgIdList.stream().distinct().collect(Collectors.toList());

                //比较通过接口上送的机构号是否包含通过商户筛选出的机构号
                if (requestOrgIdList.containsAll(mchntRealOrgList)) {
                    rglog.info("交易流水号：<{}>, 接口上送的机构信息与商户所属机构信息校验通过！", traceNo);
                } else {
                    rglog.error("交易流水号：<{}>, 接口上送的机构信息与商户所属机构信息失败！", traceNo);
                    throw new BizException(RespCodeEnum.CHECK_MCHNTREALORG_REQUESTORG_FAIL.getRespCode(), RespCodeEnum.CHECK_MCHNTREALORG_REQUESTORG_FAIL.getRespDesc());
                }
            }
        }

        OrganizationMapper organizationMapper = new OrganizationMapperImpl();
        /* 接口上送的机构信息中不包含当前机构所属的上级机构，所以需要把上属机构补充道机构信息表中*/
        //需要从接口上送的机构信息中添加的上级机构
        List<McOrgInfoBean> addOrgIdList = new ArrayList<>();
        //最终机构信息（补充完上级机构后的机构列表）
        List<McOrgInfoBean> requestResultOrgList = editCashierCashbackMcDetailRequest.getOrgInfoList();

        String queryOrgId = editCashierCashbackMcDetailRequest.getQueryOrgId();
        //查询当前登录用户的所属机构信息
        Organization queryOrgInfo = organizationMapper.selectOrganization(globalInstId, queryOrgId);
        //当前登录用户所属机构的最大深度
        int orgLevealDepth = 6;
        Boolean superOrgFlag = false;
        while (orgLevealDepth > 0) {
            if (null != queryOrgInfo) {
                if (superOrgFlag) {
                    McOrgInfoBean mcOrgInfoBean = new McOrgInfoBean();
                    mcOrgInfoBean.setOrgHierarchy(queryOrgInfo.getOrgLevel());
                    mcOrgInfoBean.setOrgId(queryOrgInfo.getOrgCode());
                    mcOrgInfoBean.setOrgName(queryOrgInfo.getOrgName());
                    mcOrgInfoBean.setOprType(CommonConstant.DEFAULT_OPR_ID);
                    addOrgIdList.add(mcOrgInfoBean);
                }
                String superOrgId = queryOrgInfo.getSuperOrgCode();
                String orgLevel = queryOrgInfo.getOrgLevel();
                rglog.info("交易流水号：<{}>,当前机构机构编码<{}>,上级机构编码<{}>,机构编码级别<{}>", traceNo, queryOrgInfo.getOrgCode(), superOrgId, orgLevel);

                if (null != superOrgId && !"00".equals(orgLevel)) {
                    rglog.info("交易流水号：<{}>,接口请求上送的机构信息中需要添加 <{}>!", traceNo, superOrgId);
                    queryOrgInfo = organizationMapper.selectOrganization(globalInstId, superOrgId);
                    superOrgFlag = true;
                } else {
                    break;
                }

                orgLevealDepth--;
            } else {
                rglog.error("交易流水号：<{}>, 机构<{}>机构信息查询失败！", traceNo, addOrgIdList.size(), queryOrgId);
                throw new BizException(RespCodeEnum.NO_ORG_INFO_ERROR.getRespCode(), RespCodeEnum.NO_ORG_INFO_ERROR.getRespDesc());
            }
        }

        if (null != addOrgIdList && !addOrgIdList.isEmpty()) {
            rglog.info("交易流水号：<{}>, 接口上送的机构机构信息中有需要添加<{}>个上级机构信息", traceNo, addOrgIdList.size());
            requestResultOrgList.addAll(addOrgIdList);
            editCashierCashbackMcDetailRequest.setOrgInfoList(requestResultOrgList);
        } else {
            rglog.info("交易流水号：<{}>, 接口上送的机构机构信息中不需要添加上级机构信息（当前用户所属机构已经为总行级别）", traceNo, addOrgIdList.size());
        }
    }

    /**
     * 检查 上送 活动信息 金额字段不能为负数
     *
     * @param cashierCashbackMcInfoBean
     * @author ls
     * @date 2020/10/21
     */
    private void checkMcInfoObjFieldHasNegativeNumber(CashierCashbackMcInfoBean cashierCashbackMcInfoBean) {
        /* 活动预算 */
        if (!StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getBudget()) && new BigDecimal(cashierCashbackMcInfoBean.getBudget()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 达标交易金额 */
        if (!StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getCriteriaAmount()) && new BigDecimal(cashierCashbackMcInfoBean.getCriteriaAmount()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 达标交易笔数 */
        if (!StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getCriteriaQuantity()) && new BigDecimal(cashierCashbackMcInfoBean.getCriteriaQuantity()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 交易笔数上限 */
        if (!StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getQuantityLimitPerson()) && new BigDecimal(cashierCashbackMcInfoBean.getQuantityLimitPerson()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 交易金额上限 */
        if (!StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getAmountLimitPerson()) && new BigDecimal(cashierCashbackMcInfoBean.getAmountLimitPerson()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 返现金额上限 */
        if (!StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getCashbackLimitPerson()) && new BigDecimal(cashierCashbackMcInfoBean.getCashbackLimitPerson()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }

        /* 交易笔数上限 */
        if (!StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getQuantityLimitMc()) && new BigDecimal(cashierCashbackMcInfoBean.getQuantityLimitMc()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 交易金额上限 */
        if (!StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getAmountLimitMc()) && new BigDecimal(cashierCashbackMcInfoBean.getAmountLimitMc()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 返现金额上限 9 */
        if (!StringUtil.isNullorEmpty(cashierCashbackMcInfoBean.getCashbackLimitMc()) && new BigDecimal(cashierCashbackMcInfoBean.getCashbackLimitMc()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
    }

    /**
     * 检查 上送 活动信息 金额字段不能为负数
     *
     * @param cashierCashbackRuleInfoBean
     * @author ls
     * @date 2020/10/21
     */
    private void checkRuleInfoFieldHasNegativeNumber(CashierCashbackRuleInfoBean cashierCashbackRuleInfoBean) {
        /* 控制下限 */
        if (!StringUtil.isNullorEmpty(cashierCashbackRuleInfoBean.getCriteriaFloor()) && new BigDecimal(cashierCashbackRuleInfoBean.getCriteriaFloor()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 控制上限 2*/
        if (!StringUtil.isNullorEmpty(cashierCashbackRuleInfoBean.getCriteriaCelling()) && new BigDecimal(cashierCashbackRuleInfoBean.getCriteriaCelling()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
    }

    /**
     * 新增商户定时任务
     *
     * @param dbsUtil
     * @param mrctFilePath
     * @throws Exception
     */
    private void insertMcTaskInfoForMerFile(DbsUtil dbsUtil, String mrctFilePath) throws Exception {
        McTaskFlowMapper taskFlowMapper = new McTaskFlowMapperImpl();
        TMMcTaskFlow flow = new TMMcTaskFlow();
        globalFlowNo = DateUtil.getCurrentDateTime("yyyyMMddHHmmssSSS") + RandomUtil.getRandomInt();
        /* 存储业务数据 */
        JSONObject bizDate = new JSONObject();
        bizDate.put("auditStatus", flowAuditStatus);
        bizDate.put("tmpAuditStatus", flowTmpAuditStatus);
        rglog.info("交易流水号：<{}>,任务流水号<{}>,新增任务流水,备份原营销活动审批状态<{}>", traceNo, globalFlowNo, bizDate.toString());

        flow.setFlowNo(globalFlowNo);
        flow.setInstId(globalInstId);
        flow.setMcNo(globalMcNo);
        flow.setBizTypeCd("");
        flow.setBizTypeParamData(bizDate.toJSONString());
        flow.setCreateTm(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
        flow.setTaskSts("00");
        flow.setFilePath(mrctFilePath);
        flow.setTxnDt(DateUtil.getCurrentDate());
        flow.setTxnTm(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
        flow.setOprId(globalOprId);
        flow.setRmrk1(traceNo);
        int returnCode = taskFlowMapper.insertMcTaskFlow(flow);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增活动上传商户文件定时任务失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
        rglog.info("创建商户文件定时任务");

    }

    /**
     * 修改任务表业务数据
     *
     * @param dbsUtil
     * @param instId
     * @param mcNo
     * @param flowNo  任务流水号
     * @param bizDate 业务数据
     * @throws Exception
     */
    private void updateMcTaskInfoBizDate(DbsUtil dbsUtil, String instId, String mcNo, String flowNo, String bizDate) throws Exception {

        McTaskFlowMapper taskFlowMapper = new McTaskFlowMapperImpl();
        int returnCode = taskFlowMapper.updateMcTaskFlowBizDate(instId, mcNo, flowNo, bizDate);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("更新商户文件定时任务业务数据失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
        rglog.info("更新商户文件定时任务业务数据，备份业务数据状态");
    }

    /**
     * 临时表中将营销活动指定商户信息删除
     *
     * @param dbsUtil          数据库操作工具类
     * @param tmPlatBizTmpList 业务数据临时表
     * @throws Exception 异常信息
     * @author liujinan
     * @since 2020/5/28 22:17
     */
    private void deleteMultiMcDetialInfoByBank(DbsUtil dbsUtil, List<TMPlatBizTmp> tmPlatBizTmpList) throws Exception {

        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        int returnCode = platBizTmpMapper.deleteMultiMcMchntListByBank(tmPlatBizTmpList);
        //兼容批量未新增临时表问题
        if (Database.DBS_SUCCESS != returnCode && Database.DBS_NOT_FOUND != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动机构信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 处理因机构变更导致需要删除的商户数据
     *
     * @param dbsUtil
     * @param orgInfoList 上传的机构列表信息
     * @throws Exception
     * @author liujinan
     * @since 2020/6/24 16:05
     */
    private void delMchntListByDelOrgList(DbsUtil dbsUtil, List<McOrgInfoBean> orgInfoList) throws Exception {
        List<String> delMchntNoList = new ArrayList<>();
        /* 查询营销活动原机构列表 */
        List<TMMcOrgInfo> newOrgInfoList = orgInfoList.stream().map(this::convertMcOrgInfo).collect(Collectors.toList());

        /* 获取上送机构列表、活动原机构列表 */
        McOrgInfoMapper mcOrgInfoMapper = new McOrgInfoMapperImpl();
        List<TMMcOrgInfo> oldOrgInfoList = mcOrgInfoMapper.selectMcOrgInfoList(globalInstId, globalMcNo);

        List<String> newOrgs = newOrgInfoList.stream().map(item -> item.getOrgId()).collect(Collectors.toList());
        List<String> hisOrgs = oldOrgInfoList.stream().map(item -> item.getOrgId()).collect(Collectors.toList());
        rglog.info("机构变更-商户信息处理流程，本次上传机构列表size:<{}>,商户:<{}>", newOrgs.size(), newOrgs.toString());
        rglog.info("机构变更-商户信息处理流程，原活动机构列表size:<{}>,商户:<{}>", hisOrgs.size(), hisOrgs.toString());
        for (String orgId : newOrgs) {
            if (hisOrgs.contains(orgId)) {
                hisOrgs.remove(orgId);
            }
        }
        rglog.info("机构变更-商户信息处理流程，排查本次机构变更数据，待删除的机构列表size:<{}>,商户:<{}>", hisOrgs.size(), hisOrgs.toString());
        if (!hisOrgs.isEmpty()) {
            rglog.info("机构变更-商户信息处理流程，查询营销活动存量商户列表信息");
            List<Object> mcMchntInfoList = getAllMcMchntListInfo();
            if (mcMchntInfoList != null && !mcMchntInfoList.isEmpty()) {
                List<McMchntInfoBean> mcMchntInfoBeanList = mcMchntInfoList.stream().map(this::convertMcMchntInfo).collect(Collectors.toList());
                List<String> mchntNoList = mcMchntInfoBeanList.stream().map(item -> item.getMchntNo()).collect(Collectors.toList());
                rglog.info("机构变更-商户信息处理流程，查询营销活动存量商户列表信息:<{}>", mchntNoList.toString());

                rglog.info("机构变更-商户信息处理流程，存在删除的机构列表，开始排查该机构下是否存在参加活动的商户");
                MchntInfoMapper mchntInfoMapper = new MchntInfoMapperImpl();
                List<TBMchntBaseInfo> mchntNoForOrgList = new ArrayList<>();
                for (String signInstId : hisOrgs) {
                    //查询该机构下所有的商户列表
                    List<TBMchntBaseInfo> mchntInfoList = mchntInfoMapper.selectMchntBaseInfoListBySignInstId(globalInstId, signInstId);
                    mchntNoForOrgList.addAll(mchntInfoList);
                }
                if (!mchntNoList.isEmpty() && !mchntNoForOrgList.isEmpty()) {
                    List<String> mchntNoListForDelOrgs = mchntNoForOrgList.stream().map(item -> item.getMchntNo()).collect(Collectors.toList());
                    for (String mchntNo : mchntNoList) {
                        if (mchntNoListForDelOrgs.contains(mchntNo)) {
                            delMchntNoList.add(mchntNo);
                        }
                    }
                    rglog.info("机构变更-商户信息处理流程，待删除机构列表下属商户列表size:<{}>,商户:<{}>", delMchntNoList.size(), delMchntNoList.toString());
                }
            }
        }
        if (!delMchntNoList.isEmpty()) {
            List<TMMcMchntInfo> delOrgsMchntInfoList = delMchntNoList.stream().map(this::convertMcMchntInfoForDel).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>删除商户列表，size<{}>", globalInstId, globalMcNo, delOrgsMchntInfoList.size());
            deleteMcMchntInfoList(dbsUtil, delOrgsMchntInfoList);
            List<TMPlatBizTmp> delOrgsMcMchntList = delOrgsMchntInfoList.stream().map(this::convertMcMchntInfoToTmpForDel).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>删除商户列表临时表，size<{}>", globalInstId, globalMcNo, delOrgsMcMchntList.size());
            deleteMultiMcDetialInfoByBank(dbsUtil, delOrgsMcMchntList);
        }

    }

    /**
     * 获取营销活动商户信息列表(正式表)
     *
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMMcMchntInfo> 营销活动商户信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/28 18:35
     */
    private List<Object> getAllMcMchntListInfo() throws Exception {
        List<Object> tmMcMchntInfoList = new ArrayList<>();
        PageInfo pageInfo = new PageInfo();
        int i = 0;
        pageInfo.setPageIndex(i);
        pageInfo.setPageSize(9999);
        TMMcMchntInfo tmMcMchntInfo = new TMMcMchntInfo();
        tmMcMchntInfo.setInstId(globalInstId);
        tmMcMchntInfo.setMcNo(globalMcNo);
        McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
        PageResult tmMcMchntInfoPageInfo = mcMchntInfoMapper.selectMcMchntInfoList(tmMcMchntInfo, pageInfo);
        if (null != tmMcMchntInfoPageInfo && null != tmMcMchntInfoPageInfo.getResult()) {
            tmMcMchntInfoList.addAll(tmMcMchntInfoPageInfo.getResult());
        }
        while (null != tmMcMchntInfoPageInfo && null != tmMcMchntInfoPageInfo.getResult() && tmMcMchntInfoPageInfo.getResult().size() >= 1) {
            i++;
            pageInfo.setPageIndex(i);
            tmMcMchntInfoPageInfo = mcMchntInfoMapper.selectMcMchntInfoList(tmMcMchntInfo, pageInfo);
            if (null != tmMcMchntInfoPageInfo && null != tmMcMchntInfoPageInfo.getResult()) {
                tmMcMchntInfoList.addAll(tmMcMchntInfoPageInfo.getResult());
            }
        }
        return tmMcMchntInfoList;
    }

    /**
     * 营销活动商户信息数据库实体类和接口实体类数据转换
     *
     * @param object 营销活动商户信息表
     * @return cc.rengu.igas.momp.facade.bean.McMchntInfoBean 营销活动商户信息对象
     * @author Jinan Liu
     * @date 2020/4/1 10:33
     */
    private McMchntInfoBean convertMcMchntInfo(Object object) {
        McMchntInfoBean mcMchntInfoBean = new McMchntInfoBean();
        TMMcMchntInfo mcMchntInfo = (TMMcMchntInfo) object;
        try {
            /* 商户范围类型 */
            mcMchntInfoBean.setMchntType(mcMchntInfo.getMchntType());
            /* 商户范围号 */
            mcMchntInfoBean.setMchntNo(mcMchntInfo.getMchntNo());
            /* 商户范围名称 */
            mcMchntInfoBean.setMchntName(mcMchntInfo.getMchntName());
            /* 新增商户标志 */
            mcMchntInfoBean.setNewMchntFlag(mcMchntInfo.getNewMchntFlag());
            /* 退出标志 */
            mcMchntInfoBean.setExitFlag(mcMchntInfo.getExitFlag());
            /* 操作类型 */
            if ((mcMchntInfo.getNewMchntFlag().equals(CommonConstant.MCHNT_REFUSE_FLAG) || mcMchntInfo.getNewMchntFlag().equals(CommonConstant.MCHNT_NEW_FLAG)) && mcMchntInfo.getExitFlag().equals(CommonConstant.MC_EXIT_FLAG)) {
                mcMchntInfoBean.setOprType(CommonConstant.BIZ_OPR_INSERT);
            } else {
                mcMchntInfoBean.setOprType(CommonConstant.EMPTY_STRING);
            }
        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", e.getMessage());
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }
        return mcMchntInfoBean;
    }

    /**
     * 营销活动商户信息数据库实体类和接口实体类数据转换
     *
     * @param mchntNo 商户号
     * @return cc.rengu.igas.momp.common.entity.TMMcMchntInfo 营销活动商户信息表
     * @author liujinan
     * @since 2021/6/24 11:10
     */
    private TMMcMchntInfo convertMcMchntInfoForDel(String mchntNo) {
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        try {
            /* 法人机构号 */
            mcMchntInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcMchntInfo.setMcNo(globalMcNo);
            /* 商户范围类型 */
            mcMchntInfo.setMchntType(CommonConstant.ZERO_COMMON_CONSTANT);
            /* 商户范围号 */
            mcMchntInfo.setMchntNo(mchntNo);
        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }
        return mcMchntInfo;
    }

    private TMPlatBizTmp convertMcMchntInfoToTmpForDel(TMMcMchntInfo tmMcMchntInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcMchntInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcMchntInfo.getMcNo());
            /* 商户编号 */
            tmPlatBizTmp.setMchntNo(tmMcMchntInfo.getMchntNo());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameCode());

            return tmPlatBizTmp;
        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }
}